<?php if (!defined('ROOT_DIR')) exit('No direct script access!');
/**
 * config.nct.core.php file
 *
 * PHP Version 5
 *
 * DateCreated - December 5, 2011
 * DateModified - December 5, 2011
 * 
 * @category  Core
 * @package   Core
 * @author    Ervin Musngi <ervinmusngi@gmail.com>
 * 
 * @copyright 2011 Ervin Musngi
 * @license   http://netcoretech.com Net-Coret-Tech
 * @version   SVN: <tortoise>
 * @link      http://netcoretech.com/php/
 * 
 */

/**
 * Config Class
 *
 * DateCreated - December 5, 2011
 * DateModified - December 5, 2011
 * 
 * Class used to load configuration files
 * 
 * @category  Core
 * @package   Core
 * @author    Ervin Musngi <ervinmusngi@gmail.com>
 * 
 * @copyright 2011 Ervin Musngi
 * @license   http://netcoretech.com Net-Coret-Tech
 * @link      http://netcoretech.com/php/
 * 
 */

class Config
{
    
    private $_config = array();
    private $_nct;
    
    /**
     *@method __construct() Initialize the autoloader  
     */
    public function __construct()
    {
        $this->_nct =& get_instance();
        
        $autoload_config = get_config('autoload', 'autoload');
        
        foreach ( $autoload_config['config'] as $conf ) {
            $this->load($conf);
        }
        
    }
    
    /**
     *@method load() Load Specified Configuration file.
     * 
     * @param string $config_name - The name of the configuration file.
     * 
     * Here is an inline example :
     * <code>
     *   $this->config->load('nct');
     * </code>
     * 
     * @return void - Nothing are being return from this method.
     */
    public function load( $config_name )
    {
        GLOBAL $application_folder,$system_folder;
        
        if ( file_exists(ROOT_DIR.'/'.$application_folder.'/config/config_'.$config_name.'.php') ) {
            
            include_once ROOT_DIR.'/'.$application_folder.'/config/config_'.$config_name.'.php' ;
            
            $this->_config = array_merge($this->_config, $config);
        } else {
            
            if ( ERROR_REPORT === true ) {
                $path = ROOT_DIR.'/'.$application_folder.'/config/config_'.$config_name.'.php';
                include_once ROOT_DIR.'/'.$system_folder.'/error/fileNameDoesntExist.php';
            }
            
            exit();
            
        }
        
    }
    
    /**
     *@method item() Get the array containing the configurations.
     * 
     * @param string $item - The name of the item array.
     * 
     * Here is an inline example :
     * <code>
     *   $config = $this->config->item('email');
     * </code>
     * 
     * @return Array
     */
    public function item( $item = '' )
    {
        if ( isset($this->_config[$item]  ) ) {
            return $this->_config[$item];
        } else {
            return null;
        }
    }
    
}